package com.longer.playhelper.view.fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import android.widget.TextView;

import com.longer.playhelper.Application;
import com.longer.playhelper.R;
import com.longer.playhelper.utlis.FileTools;
import com.longer.playhelper.utlis.PublicTools;
import com.longer.playhelper.view.activity.LoginPhone_Activity;
import com.longer.playhelper.view.activity.MainActivity;
import com.longer.playhelper.view.activity.SendBug_Activity;
import com.longer.playhelper.view.activity.UserInfor_Activity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UserFragment extends Fragment {

    @Bind(R.id.tv_user_phone_state)
    TextView tvUserPhoneState;
    Context context;
    @Bind(R.id.switch_theme)
    Switch switchTheme;
    private View view;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_user, null);
        context = getActivity();
        ButterKnife.bind(this, view);

//        getTheme();
        return view;
    }

    @Override
    public void onStart() {
        if(Application.my != null){
            tvUserPhoneState.setText("已登录");
            tvUserPhoneState.setTextColor(getResources().getColor(R.color.textview_ok));
        }
        super.onStart();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


    @OnClick({R.id.card_user_infor, R.id.switch_theme, R.id.card_user_collection, R.id.card_user_send, R.id.card_user_id, R.id.card_user_share, R.id.card_user_message, R.id.card_user_store, R.id.card_user_setting})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.switch_theme:
                MainActivity mainActivity = MainActivity.instance;
                if (switchTheme.isChecked()) {//晚上
                    mainActivity.setTheme(true);
                    FileTools.saveshareString("theme", "night");
                } else {
                    mainActivity.setTheme(false);
                    FileTools.saveshareString("theme", "day");
                }
                break;
            case R.id.card_user_infor:
                startActivity(new Intent(context, UserInfor_Activity.class));
                break;
            case R.id.card_user_collection:
                break;
            case R.id.card_user_send:
                break;
            case R.id.card_user_id:
                startActivity(new Intent(context, LoginPhone_Activity.class));
                break;
            case R.id.card_user_share:
                PublicTools.shareapp(context);
                break;
            case R.id.card_user_message:
                startActivity(new Intent(context, SendBug_Activity.class));
                break;
            case R.id.card_user_store:
                PublicTools.comment(context);
                break;
            case R.id.card_user_setting:
                break;
        }
    }
}
